package com.iweipan.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.iweipan.R;
import com.iweipan.adapter.MyQuanAdapter;
import com.iweipan.base.WPBaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by xyb on 2016/12/21.
 */

public class MyQuanActivity extends WPBaseActivity implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener {

    MyQuanAdapter myQuanAdapter;
    @BindView(R.id.iv_section_title_back)
    ImageView ivSectionTitleBack;
    @BindView(R.id.ll_section_title_back)
    LinearLayout llSectionTitleBack;
    @BindView(R.id.tv_section_title_title)
    TextView tvSectionTitleTitle;
    @BindView(R.id.tv_section_title_right)
    TextView tvSectionTitleRight;
    @BindView(R.id.ll_section_title_right)
    LinearLayout llSectionTitleRight;
    @BindView(R.id.rl_section_title)
    RelativeLayout rlSectionTitle;
    @BindView(R.id.one)
    RadioButton one;
    @BindView(R.id.two)
    RadioButton two;
    @BindView(R.id.three)
    RadioButton three;
    @BindView(R.id.order_radioGroup)
    RadioGroup orderRadioGroup;
    @BindView(R.id.myQuan_viewpager)
    ViewPager myQuanViewpager;

    @Override
    public int bindLayout() {
        return R.layout.activity_myquan;
    }

    @Override
    public void initToolbarColor() {

    }

    @Override
    public void initView(View view) {
        tvSectionTitleTitle.setText("我的银元券");
        Intent intent = getIntent();
        myQuanAdapter = new MyQuanAdapter(getSupportFragmentManager(), intent.getStringExtra("token"));
        String my_quan_string = intent.getStringExtra("my_quan_string");
        if (my_quan_string != null) {

        }
    }

    @Override
    public void doBusiness(Context mContext) {
        orderRadioGroup.setOnCheckedChangeListener(this);
        myQuanViewpager.setAdapter(myQuanAdapter);
        myQuanViewpager.addOnPageChangeListener(this);
        myQuanViewpager.setOffscreenPageLimit(2);
    }

    @Override
    public void resume() {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.one:
                myQuanViewpager.setCurrentItem(0);
                break;
            case R.id.two:
                myQuanViewpager.setCurrentItem(1);
                break;
            case R.id.three:
                myQuanViewpager.setCurrentItem(2);
                break;
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                one.setChecked(true);
                break;
            case 1:
                two.setChecked(true);
                break;
            case 2:
                three.setChecked(true);
                break;
        }

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }




    @OnClick(R.id.iv_section_title_back)
    public void onClick() {
        if (this != null) {
            finish();
        }

    }
}
